import java.util.Scanner;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/5/17
 * Time:8:29
 **/
public class Main2 {
    /**
     * 每日一题-数根
     * 不能解决超长数字
     *
     * @param args
     */
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.nextLine();
            while (str.length() > 1) {
                int result = 0;
                for (int i = 0; i < str.length(); i++)
                    result += str.charAt(i) - '0';
                str = String.valueOf(result);
            }
            System.out.println(str);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.nextLine();
            while (str.length() > 1) {
                int sum = 0;
                for (int i = 0; i < str.length(); i++) {
                    sum += str.charAt(i) - '0';//转成数字累加
                }
                str = String.valueOf(sum);//将sum转为String赋给str
            }
            System.out.println(str);
        }
    }

}
